<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>报关资料发送提醒管理</title>
    <s:head/>
</head>
<script type="text/javascript">
    function update() {
        var id = $("#declarationInformsDataGrid").jqGrid("getGridParam",
                "selrow");
        if (id) {
            var ret = $("#declarationInformsDataGrid").jqGrid('getRowData', id);
            var t = ret["declaration.id"];
            //$('#center', window.parent.document).attr("src","declarationInform-manage?declarationInform.ID="+ret.ID);
            //window.location.href="declarationInform-manage?declarationInform.id="+ret.id + "&declarationInform.sendRemind.id=" +t;
            jw.dialog({
                iframe: "declarationInform-manage?declarationInform.id=" + ret.id + "&declarationInform.sendRemind.id=" + t,
                width: 500,
                height: 100,
                over: false
            });
        } else {
            jw.alert("请点击需要修改的数据!");
        }
    }

    function imageFormat(cellvalue, options, rowObject) {
        return '<a href="#" onclick="update()">' + cellvalue + '</a>';
    }

    var formSetting = {
        title: "报关资料发送提醒管理",
        module: 'query',
        columns: [{
            name: "CTIME",
            label: "发送日期从",
            type: "date"
        }, {
            name: "CTIME",
            label: "到",
            type: "date"
        }],
        buttons: {
            custom: [
                {
                    id: "addbtn",
                    value: "新增",
                    click: function () {
                        //$('#center', window.parent.document).attr("src","declarationInform-save");
                        window.location.href = "declaration-main";
                    }
                },
                {
                    id: "updateBtn",
                    value: "修改",
                    click: update
                    /* function() {
                     var id = $("#declarationInformsDataGrid").jqGrid("getGridParam",
                     "selrow");
                     if (id) {
                     var ret = $("#declarationInformsDataGrid").jqGrid('getRowData',id);
                     var t = ret["declaration.id"];
                     //$('#center', window.parent.document).attr("src","declarationInform-manage?declarationInform.ID="+ret.ID);
                     //window.location.href="declarationInform-manage?declarationInform.id="+ret.id + "&declarationInform.sendRemind.id=" +t;
                     jw.dialog({
                     iframe :"declarationInform-manage?declarationInform.id="+ret.id + "&declarationInform.sendRemind.id=" +t,
                     width : 500,
                     height : 100,
                     over : false
                     });
                     } else {
                     jw.alert("请点击需要修改的数据!");
                     }
                     }  */
                },
                {
                    id: "delbtn",
                    value: "删除",
                    click: function () {
                        var selectedIds = $("#declarationInformsDataGrid").jqGrid(
                                "getGridParam", "selarrrow");
                        if (selectedIds.length > 0) {
                            jw.confirm("确定要删除选择的项?", function () {
                                        var data = "id=";
                                        for (i in selectedIds) {
                                            var ret = $("#declarationInformsDataGrid").jqGrid('getRowData', selectedIds[i]);
                                            data += ret.ID + ",";
                                        }
                                        data = data.substring(0, data.length - 1);
                                        $.ajax({
                                            url: "declarationInform-del",
                                            dataType: "json",
                                            data: data,
                                            success: function (data) {
                                                jw.alert(data.msg);
                                                $("#declarationInformsDataGrid").jqGrid("setGridParam",
                                                        {
                                                            search: true
                                                            // 将jqGrid的search选项设为true
                                                        }).trigger("reloadGrid", [{
                                                    page: 1
                                                }]);
                                            }
                                        });
                                    },
                                    function () {
                                        return;
                                    });

                        } else {
                            jw.alert("请点击需要删除的数据!");
                        }

                    }
                }]
        },
        grid: {
            id: "declarationInformsDataGrid",
            title: "查询结果",
            url: "declarationInform-findList",
// 			multiselect : true,
            colModel: [{
                index: "ID",
                name: "id",
                hidden: true
            }, {
                index: "biz_id",
                name: "declaration.id",
                label: "相关报关业务",
                formatter: 'showlink',
                formatoptions: {showAction: 'declaration-bizView'},
                hidden: true
            }, {
                index: "declaration.businessId",
                name: "declaration.businessId",
                formatter: imageFormat,
// 				formatter:'showlink',
// 				formatoptions: {showAction:'declarationInform-manage', idName:'declarationInform.id',target : ''},
// 				onCellSelect:update,
                label: "报关业务编号"
            }, {
                index: "sup_company_id",
                name: "supCompany.id",
                hidden: true
            }, {
                index: "sup_company",
                name: "supCompany.name",
                label: "业务供应商"
            }, {
                index: "confirmState",
                name: "confirmState",
                label: "接收状态"
            }, {
                index: "company_name",
                name: "declaration.company_name",
                label: "经营单位名称"
            }, {
                index: "sendRemind.expressNo",
                name: "sendRemind.expressNo",
                label: "快递单号"
            }, {
                index: "sendRemind.expressCompanyName",
                name: "sendRemind.expressCompanyName",
                label: "快递公司名称"
            }, {
                index: "sendRemind.mailFileContents",
                name: "sendRemind.mailFileContents",
                label: "邮寄文件内容",
                hidden: true
            }, {
                index: "confirmTime",
                name: "confirmTime",
                label: "提醒确认时间",
                formatter: 'date',
                formatoptions: {srcformat: 'Y-m-d H:i:s', newformat: 'Y-m-d H:i:s'}
            }, {
                index: "CTIME",
                name: "createTime",
                label: "提醒创建时间",
                formatter: 'date',
                formatoptions: {srcformat: 'Y-m-d H:i:s', newformat: 'Y-m-d H:i:s'}
            }, {
                index: "sendRemind.remark",
                name: "sendRemind.remark",
                label: "备注"
            }],
            sortname: "businessId",
            sortorder: "desc",
            jsonReader: {
                root: "declarationInforms"
            },
            loadComplete: function (data) {
                var ids = $("#declarationInformsDataGrid").getDataIDs();
                for (var i = 0; i < ids.length; i++) {
                    var arrayData = $("#declarationInformsDataGrid").getRowData(ids[i]);
                    if (arrayData.confirmState == "0") {
                        $("#declarationInformsDataGrid").setCell(ids[i], "confirmState", "待确认");
                    }
                    else if (arrayData.confirmState == "1") {
                        $("#declarationInformsDataGrid").setCell(ids[i], "confirmState", "已确认接收");
                        $($("#" + arrayData.id).find("td")[5]).addClass("biz_state_finish");
                    }
                }
            }
        }
    };
    $(document).ready(function () {
        $("#declarationInformsDataTable").mrdForm(formSetting);
    });
</script>
<body>
<div id="declarationInformsDataTable"></div>
</body>
</html>
